package com.apes.fn.server.servicePlan.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * @program: apes-server
 * @description:
 * @author: czs
 * @create: 2023-04-21 11:46
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = QualityDetail.CONST_TABLE_NAME,indexes = {
        @Index(columnList = "quality_order_id"),
        @Index(columnList = "plan_id", unique = true)
})
public class QualityDetail extends Model {
    public static final String CONST_TABLE_NAME = "ser_quality_detail";

    @Id
    @Column(name = "id", nullable = false, length = 24)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "质检详情编码",  padding = 10 )
    private String id;

    @Column(name = "quality_order_id", nullable = false, length = 200)
    @Comment("总检单号")
    private String qualityOrderId;

    @Column(name = "plan_id", nullable = false, length = 32)
    @Comment("方案编码")
    private String planId;

    @Column(name = "operator_id", nullable = false, length = 32)
    @Comment("操作人")
    private String operatorId;

    @Column(name = "quality_test_pic", length = 4000)
    @Comment("质检图片")
    private String qualityTestPic;

    @Column(name = "quality_test_date")
    @Comment("质检时间")
    private Date qualityTestDate;

    @Column(name = "err_msg", length = 400)
    @Comment("错误信息")
    private String errMsg;

    @Column(name = "quality_flag", nullable = false, columnDefinition = "number(1,0) default 1")
    private boolean qualityFlag;

    @Column(name = "finish", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否完成")
    private boolean finish; //是否完成

    public String findAggregateId(){
        return "QualityTest:"+this.planId;
    }

}
